<?php

class Core_Backend_Component_Customer_View_Product_Index extends Core_Backend_Share_View_Grid {

    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('customer/index/index'), $this->__('share.button.back'));
        parent::buildToolbar($toolbar);
        if ($this->getIdentity()->isInRole('customer_productreviewer')) {
            $group = $toolbar->createGroup('status');
            $group->addButton($this->__('share.button.publish'))
                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(NULL, 'publish') . "')");
            $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "forbidGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(NULL, 'forbid') . "')");
        }
        $group = $toolbar->createGroup();
        $group->addLink($this->getUrl(array('poiid' => $this->getShop()->getId()), 'create'), $this->__('share.button.create'));
    }

    protected function buildGrid($grid) {
        $grid->setId('product_grid')
                ->setPrimaryKey('id');
        $grid->addLabelColumn($this->__('catalogue.label.name'), 'name', '{name}');
        $grid->addLabelColumn($this->__('share.label.tag'), 'tag', '{tag}')
                ->setWidth(200);
        $grid->addLabelColumn($this->__('catalogue.label.creator'), 'creator', '{creator}')
                ->setWidth(60);
        $grid->addDatetimeColumn($this->__('catalogue.label.created_time'), 'created_time', '{created_time}')
                ->setWidth(100);
        $grid->addLabelColumn($this->__('catalogue.label.status'), 'status', '{{lang "status.publication.{status}"}}')
                ->setWidth(80)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        parent::buildPagination($pagination);
        $pagination->setUrlFormat($this->getPaginationUrl())
                ->setRecordCount($this->getRecords());
    }

}